insert
    overwrite
    table jms_dm.dm_mng_special_need_waybill_summary_dt
    partition
    (dt)
select network_code                   as network_code      --网点编码
     , network_name                   as network_name      --网点名称
     , agent_code                     as agent_code        --代理区编码
     , agent_name                     as agent_name        --代理区名称
     , fran_code                      as fran_code         --加盟商区编码
     , fran_name                      as fran_name         --加盟商区名称
     , virt_code                      as virt_code         --虚拟代理区编码
     , virt_name                      as virt_name         --虚拟代理区名称
     , deliver_user_code              as deliver_user_code --最晚派件员编码
     , deliver_user_name              as deliver_user_name --最晚派件员名字
     , date_time                      as date_time         --日期
     , type                           as type              --类型1代表1签收时间2代表派件时间
     , count(1)                       as special_num       --特殊需求票数
     , sum(if(is_door = 1, 1, 0))     as door_num          --送货上门票数
     , sum(if(is_contact = 1, 1, 0))  as contact_num       --派签电联票数
     , sum(if(is_send_msg = 1, 1, 0)) as send_msg_num      --短信通知票数
     , sum(if(is_reback = 1, 1, 0))   as reback_num        --退回票数
     , dt                                dt                --分区
from jms_dm.dm_mng_special_need_waybill_detail_dt t1
where dt <= '{{ execution_date | cst_ds }}'
  and dt >= date_add('{{ execution_date | cst_ds }}', -6)
group by network_code
       , network_name
       , agent_code
       , agent_name
       , fran_code
       , fran_name
       , virt_code
       , virt_name
       , deliver_user_code
       , deliver_user_name
       , date_time
       , dt
       , type
    distribute by dt
